/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/11
 * Time:20:35
 */
public class Solution {
//    public int missingNumber(int[] nums) {
//        //哈希的思想
//        int[] temp = new int[nums.length + 1];
//        for (int num : nums) {
//            temp[num]++;
//        }
//        for(int i = 0;i < temp.length;i++){
//            if(temp[i] == 0){
//                return i;
//            }
//        }
//        return -1;
//    }
//    public static void main(String[] args) {
//        Solution solution = new Solution();
//        int ret = solution.missingNumber(new int[]{1,2,3,4,5});
//        System.out.println(ret);
//    }
    public int missingNumber(int[] nums) {
        int length = nums.length;
        int begin = nums[0];
        for (int i = 1; i < length; i++) {
            begin ^= nums[i];
        }
        int temp = 0;
        for (int i = 1; i <= length; i++) {
            temp ^= i;
        }
        return temp ^ begin;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int ret = solution.missingNumber(new int[]{1, 2, 3, 4, 5});
        System.out.println(ret);
    }
}
